using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using System.Runtime.Serialization;
using EnvDTE80;
using Microsoft.Practices.RecipeFramework.Extensions.References.VisualStudio; 

namespace Microsoft.Practices.RepositoryFactory.References
{
    /// <summary>
    /// UnBoundRecipeReference that allows to be executed only on a Vs Solution Folder
    /// </summary>
    [Serializable]
    public class SolutionFolderReference : CSharpLanguageReference
    {
        /// <summary>
        /// UnBoundRecipeReference that allows to be executed only on a Vs Solution Folder
        /// </summary>
        public SolutionFolderReference(string recipe)
            : base(recipe)
        {
        }

        /// <summary>
        /// Returns a friendly name as Any Solution Folder
        /// </summary>
        public override string AppliesTo
        {
            get { return Properties.Resources.SolutionFolderReference; }
        }

        /// <summary>
        /// Performs the validation of the item passed as target
        /// Returns true if the reference is allowed to be executed in the target
        /// that is if the target is a Solution Folder
        /// </summary>
        /// <param name="target"></param>
        /// <returns></returns>
        public override bool OnIsEnabledFor(object target)
        {
            Project project = target as Project;

            if(project != null)
            {
                SolutionFolder solutionFolder = project.Object as SolutionFolder;
                return solutionFolder != null;
            }
            else
            {
                return false;
            }
        }

        #region ISerializable Members

        /// <summary>
        /// Required constructor for deserialization.
        /// </summary>
        protected SolutionFolderReference(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        #endregion ISerializable Members
    }

}
